var oTxt;
var oDiv;
window.onunload = ChatExit;

function ChatExit()
{
  oTxt.value = "<i>[exited]</i>";
  DoChatCallBack(oTxt);
}

function ChatEnter()
{
  oTxt = document.getElementById("WebChat1_tbxMessageInput");
  oDiv = document.getElementById("WebChat1_pnlRoomWindow");
  oTxt.value = "<i>[entered]</i>";
  DoChatCallBack(oTxt);
  window.setTimeout("DoChatCallBack()", 2000);
}
  
var WebChatMaxMsgID = 0;
var WebChatTimeoutID;
function CalledBack(result, context)
{
    if (result.length>0)
    {
        var aryRows = result.split("~~");
        for (var iRow=0 ; iRow<aryRows.length; iRow++)
        {
            var aryCols = aryRows[iRow].split("||");
            if (parseInt(aryCols[0])>parseInt(WebChatMaxMsgID))
            {
                oDiv.innerHTML = oDiv.innerHTML + '<br>' + aryCols[1]; 
                oDiv.scrollTop = oDiv.scrollHeight;
                WebChatMaxMsgID = aryCols[0];
            }            
        }
        document.getElementById('WebChat1_tbxMessageInput').focus();
    }
    //ensure sure there is exactly one timer going at a time
    window.clearTimeout(WebChatTimeoutID);
    WebChatTimeoutID=window.setTimeout("DoChatCallBack()", 2000);
}
function ErrCalledBack(result,context){alert('Unexpected Chat Error: ' + result);}